<%--
    Document   : oEspecifico
    Created on : 14/04/2010, 11:48:03 AM
    Author     : LAPTOP01
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://struts.apache.org/tags-bean"  prefix="bean"%>
<%@taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="/tags/c" prefix="c"%>
<%@ include file="seguridad.jsp" %>


<script src="scripts/ajax.js" language="JavaScript"></script>
<html>

    <head>
        <script LANGUAGE="JavaScript">

            /*function APermanente(cod,desc){
                var codEst=document.getElementById("descObj").value;
                var form=document.getElementById("PEIForm");
                form.action="PEI.do?dispatch=listarAPermanente&codOEst="+codEst+"&cod="+cod+"&desc="+desc;

                form.method="post";
                form.submit();

            }*/
            function confirmActionGuardar(){
                if (confirm("Se Guardara los cambios hechos en la pantalla  \n ¿Esta seguro de continuar? "))
                    return true;
                else
                    return false;

            }

            function regresar(){

                var form = document.getElementById("PEIForm");
                form.action="PEI.do?dispatch=listarOEstrategico&num=10&descObj=";
                form.method="post";
                form.submit();

            }

              function APermanente(cod,idoes,desc){
                var idObj=document.getElementById("idObj").value;
                var idObje=idoes;
                var codOGE=document.getElementById("codObj").value;

                var codEst=document.getElementById("descObj").value;
                var form=document.getElementById("PEIForm");
                form.action="PEI.do?dispatch=listarAPermanente&codOEst="+codEst+"&cod="+cod+"&desc="+desc+"&codOGE="+codOGE+"&idObj="+idObj+"&idObje="+idObje;

                form.method="post";
                form.submit();


            }
            function insertar(){

                if (confirmActionGuardar()==false) return;
                var tipo=document.getElementById("opcion").value;
                var codigo =document.getElementById("cod").value;
                var codObjEst = document.getElementById("codObj").value;
                var idObje = document.getElementById("idObje").value;
                var desc = document.getElementById("descObjEsp").value;
                if(codigo==0){
                    var codigo =0;
                }

                var idDiv = "divTabla";
                var metodo = "GET";
                var url = "consultasAjax/listarOEspecificoAjax.jsp?desc="+desc+"&codigo="+codigo+"&tipo="+tipo+"&codOEst="+codObjEst+"&idObje="+idObje;
                var cadenaSalida = "";
                var async = true;
                document.getElementById(idDiv).innerHTML;
                autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
                document.getElementById("opcion").value=1;
                document.getElementById("descObjEsp").value="";
                document.getElementById("contador").value="0";
            }

            function contar(texto,e){

                document.getElementById("contador").value=document.getElementById("descObjEsp").value.length;

                if (texto.length > 500 ) {
                    if (navigator.appName == "Netscape") tecla = e.which
                    else tecla = e.keyCode
                    if (tecla != 8) return false
                }
                return true

            }
            function validar(){
                if (document.getElementById("descObjEsp").value==""){
                    alert("Ingrese la Descripcion del Objetivo Especifico");
                    document.getElementById("descObjEsp").focus();
                    return;
                }
                insertar();
            }

            function editar(desc,cod,idoe){
                var form = document.getElementById("PEIForm");
                document.getElementById("opcion").value=2;
                document.getElementById("cod").value=cod;
                form.idObje.value = idoe;
                form.descObjEsp.value = desc;
                document.getElementById("contador").value=form.descObjEsp.value.length;
            }

            function eliminar(codigo){
                if (confirmAction()==false) return;
                var desc = "m";
                var idObje = 0;
                //alert(desc);
                var idDiv = "divTabla";
                var metodo = "GET";
                var tipo = 3;
                var codObjEst=document.getElementById("codObj").value;
                var url = "consultasAjax/listarOEspecificoAjax.jsp?desc="+desc+"&codigo="+codigo+"&tipo="+tipo+"&codOEst="+codObjEst+"&idObje="+idObje;;
                var cadenaSalida = "";
                var async = true;
                document.getElementById(idDiv).innerHTML;
                autoCompletarDiv(metodo,url,cadenaSalida,async,idDiv);
                // alert("hola");
            }

            function confirmAction(){
                if (confirm("Se borrara Objetivo Especifico, meta  ,Actividades Permanentes ,  y componentes del registro seleccionado  \n ¿Esta seguro de continuar? "))
                    return true;
                else return false;
            }

            function autoCompletarDiv(metodo,url,cadena,async,idDiv)
            {
                if( window.XMLHttpRequest )
                    ajax = new XMLHttpRequest(); // No Internet Explorer
                else
                    ajax = new ActiveXObject("Microsoft.XMLHTTP");
                ELEMENT_DIV = idDiv;
                // alert("metodo-->>"+metodo+" url-->>"+url+" cadena-->>"+cadena+" async-->"+async+" idDiv-->>"+idDiv)
                ajax.onreadystatechange = funcionCallbackVerDiv;
                //alert("cadena del mal"+cadena);
                ajax.open( metodo, url, async);
                ajax.send(cadena);
            }

            function funcionCallbackVerDiv()
            {
                if( ajax.readyState == 4 )
                {
                    if( ajax.status == 200 )
                    { //alert(ajax.responseText);
                        document.getElementById(ELEMENT_DIV).innerHTML = ajax.responseText;
                    }
                }
            }


            function posicioninicial(){
            document.getElementById("idObje").focus();

        }



        </script>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <link type="text/css" rel="stylesheet" href="lib/css/Style_Font_Text.css" >
        <link type="text/css" rel="stylesheet" href="lib/css/Style_PageTable.css" >
        <link type="text/css" rel="stylesheet" href="lib/css/Style_Index.css" >


        <title>JSP Page</title>
    </head>

    <body>

        <center>
            <h1 class="substylo">Objetivo  Estrat&eacute;gico Espec&iacute;fico</h1>
        </center>
        <div style="overflow: auto; width:710px; height: 400px">
                        <html:form action="PEI.do?dispatch=ingresarOEspecifico" styleId="PEIForm">

                            <html:hidden property="opcion" styleId="opcion" value="1"/>
                            <input type="hidden"  name="cod"  id="cod"/>
                            <html:hidden property="codObj"  styleId="codObj"/>
                            <html:hidden property="idObj"  styleId="idObj"/>

                            <%int i = 1;%>
                            <br><br>


                            <table>
                                <tr><td  style="width: 150px">
                                        N&uacute;mero Objetivo General Estrat&eacute;gico:
                                    </td>
                                    <td  style="width: 400px">
                                        <html:text property="idObj"  styleId="idObj" disabled="true"/>

                                    </td>
                                </tr>
                                <tr>
                                    <td  style="width: 150px">
                                        Objetivo General Estrat&eacute;gico:
                                    </td>
                                    <td  style="width: 400px">
                                        <html:textarea property="descObj" readonly="true" styleId="descObj" disabled="true"  rows="5" cols="50" styleClass="textarea"/>

                                    </td>
                                </tr>

                                <tr><td  style="width: 150px">
                                        N&uacute;mero Objetivo Espec&iacute;fico :
                                    </td>
                                    <td  style="width: 400px">
                                        <html:text  styleId="idObje" property="idObje" maxlength="5" styleClass="text"/>

                                    </td>
                                </tr>

                                <tr>
                                    <td  style="width: 150px">Ingresar Objetivo Espec&iacute;fico :</td>
                                    <td style="width: 400px">
                                        <html:textarea property="descObjEsp" styleId="descObjEsp" rows="5" cols="50" onkeydown="return contar(this.value,event)" onkeyup="return contar(this.value,event)" styleClass="textarea" />
                                        <input type="text" size="2" id="contador"/><label style="color: #990033" >M&aacute;ximo 500 caracteres</label>
                                    </td>


                                </tr>


                                <tr>
                                    <td colspan="2" align="center"><input type="button" value="Grabar" onclick="validar()" class="submit2"/></td>
                                </tr>
                            </table>

                            <logic:present name="PEIForm" property="listaOEstrategico">
                                <div id="divTabla" style="width:100%">
                                    <table id="tabla1" width="99%" align="right" class="userTable">
                                        <tr class="even" align="center">
                                            <th class="textoTR">N&uacute;mero</th>
                                            <th class="textoTR">Objetivo  Estrat&eacute;gico Espec&iacute;fico</th>
                                            <th class="textoTR">Editar</th>
                                            <th class="textoTR">Eliminar</th>
                                            <th class="textoTR">Actividad Estrat&eacute;gica</th>

                                        </tr>
                                        <logic:iterate name="PEIForm" property="listaOEspecifico" id="lista">
                                            <tr align="center">
                                                <td  align="center">
                                                    <bean:write name="lista" property="NUM_IDOBJ"/>.<bean:write name="lista" property="NUM_IDOBJESP"/>
                                                </td>

                                                <td align="center" style="width:1500px;text-align: left">
                                                    <bean:write name="lista" property="TX_DESCOBJESP"/>
                                                </td>

                                                <td  align="center">

                                                    <img style="cursor:pointer" title="Editar" alt="Editar" border=0  src="images/b_edit.png" onclick="editar('<c:out value="${lista.TX_DESCOBJESP}"/>','<c:out value="${lista.NUM_CODOBJESP_PK}"/>','<c:out value="${lista.NUM_IDOBJESP}"/>');posicioninicial();"/>

                                                </td>

                                                <td  align="center">

                                                    <img style="cursor:pointer" title="Eliminar" title="Eliminar" alt="Eliminar" border=0  src="images/b_drop.png" onclick="eliminar('<c:out value='${lista.NUM_CODOBJESP_PK}'/>');">
                                                </td>

                                                <td  align="center">

                                                    <img style="cursor:pointer" title="Meta" title="Meta" alt="Meta" border=0  src="images/file_preview.png" onclick = "APermanente('<c:out value='${lista.NUM_CODOBJESP_PK}'/>','<c:out value="${lista.NUM_IDOBJESP}"/>','<c:out value='${lista.TX_DESCOBJESP}'/>');">
                                                </td>



                                            </tr>
                                        </logic:iterate>
                                    </table>
                                </div>
                            </logic:present>
                 <html:button property="button"  value="regresar" onclick="regresar()" styleClass="submit2" />


        </html:form>
</div>
    </body>
</html>
